local extension = Package:new("wq_fennu")
extension.extensionName = "FkWqmt"
Fk:loadTranslationTable{
  ["wq_fennu"] = "无期迷途·愤怒",
}

local Wqc = require "packages/FkWqmt/wq_common"
local U = require "packages/utility/utility"

-- 禁闭者：迪蒙
local wq_dimeng = General:new(extension, "wq_dimeng", "qun", 3, 4, General.Male)
wq_dimeng.shield = 2
-- 技能：盾身
local wq_skill_dunshen = fk.CreateTriggerSkill{
  name = "wq_skill_dunshen",
  anim_type = "support",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and target.phase == Player.Finish and player == target and player:isWounded()
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local targets = table.map(room.alive_players, function(p) return p.id end)
    local prompt = "#wq_skill_dunshen-choose:::"..player:getLostHp()
    local tos = room:askForChoosePlayers(player, targets, 1, player:getLostHp(), prompt, self.name, true)
    if #tos > 0 then
      self.cost_data = tos
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    for _, id in ipairs(self.cost_data) do
      local p = room:getPlayerById(id)
      if p:isAlive() then
        room:changeShield(p, 1)
      end
    end
  end,
}
-- 技能：鼓舞
local wq_skill_guwu = fk.CreateTriggerSkill{
  name = "wq_skill_guwu",
  anim_type = "support",
  events = {fk.Damage},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and target and target:isAlive() and target.shield > 0 and player:usedSkillTimes(self.name, Player.HistoryTurn) == 0
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    return room:askForSkillInvoke(player, self.name, data, "#wq_skill_guwu_prompt:"..target.id.."::"..target.shield)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:drawCards(target, target.shield, self.name)
  end,
}
local wq_skill_guwu_maxcard = fk.CreateMaxCardsSkill{
  name = "#wq_skill_guwu_maxcard",
  correct_func = function(self, player)
    if player.shield > 0 then
      local num = #table.filter(Fk:currentRoom().alive_players, function(p)
        return p:hasSkill("wq_skill_guwu")
      end)
      return num * player.shield
    end
  end,
}
wq_skill_guwu:addRelatedSkill(wq_skill_guwu_maxcard)
-- 技能：自戕
local wq_skill_ziqiang = fk.CreateActiveSkill{
  name = "wq_skill_ziqiang",
  anim_type = "defensive",
  frequency = Skill.Limited,
  card_num = 0,
  target_num = 0,
  prompt = function (self, selected, selected_cards)
    local num = Self.hp - 1
    return "#wq_skill_ziqiang_prompt:::"..num
  end,
  can_use = function(self, player)
    return player.hp > 1 and player:usedSkillTimes(self.name, Player.HistoryGame) == 0
  end,
  card_filter = Util.FalseFunc,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local num = player.hp - 1
    room:loseHp(player, num, self.name)
    if player:isAlive() then
      room:drawCards(player, num, self.name)
      room:changeShield(player, num)
    end
  end,
}
-- 迪蒙技能
wq_dimeng:addSkill(wq_skill_dunshen)
wq_dimeng:addSkill(wq_skill_guwu)
wq_dimeng:addSkill(wq_skill_ziqiang)
-- 迪蒙翻译
Fk:loadTranslationTable{
  ["wq_dimeng"] = "迪蒙",
  ["#wq_dimeng"] = "防御力场",
  ["designer:wq_dimeng"] = "妙霄",
  ["cv:wq_dimeng"] = "官方",
  ["illustrator:wq_dimeng"] = "官方",
  ["wq_skill_dunshen"] = "盾身",
  [":wq_skill_dunshen"] = "结束阶段，你可以令至多X名角色获得1点护甲（X为你已损失的体力值）。",
  ["$wq_skill_dunshen"] = "休想跨过我！",
  ["#wq_skill_dunshen-choose"] = "盾身：你可以令至多 %arg 名角色获得1点护甲",
  ["wq_skill_guwu"] = "鼓舞",
  [":wq_skill_guwu"] = "每回合限一次，一名角色造成伤害后，你可以令其摸X张牌。锁定技，每名角色的手牌上限+X（X为该角色的护甲值）。",
  ["$wq_skill_guwu"] = "行动开始，全员警戒。",
  ["#wq_skill_guwu_prompt"] = "鼓舞：你可以令%src摸 %arg 张牌",
  ["wq_skill_ziqiang"] = "自戕",
  [":wq_skill_ziqiang"] = "限定技，出牌阶段，你可以失去X点体力。若如此做，你摸等量张牌，并获得等量护甲（X为你的体力值-1）。",
  ["$wq_skill_ziqiang1"] = "是时候了，我必须兑现承诺。",
  ["$wq_skill_ziqiang2"] = "我不会让你们失望的，不再会了……",
  ["#wq_skill_ziqiang_prompt"] = "自戕：你可以失去 %arg 点体力，摸 %arg 张牌并获得 %arg 点护甲",
  ["~wq_dimeng"] = "我……辜负了你……",
}

-- 禁闭者：赫罗
local wq_heluo = General:new(extension, "wq_heluo", "qun", 3, 4, General.Female)
-- 技能：天崩
local wq_skill_tianbeng = fk.CreateTriggerSkill{
  name = "wq_skill_tianbeng",
  anim_type = "offensive",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and player == target and player.phase == Player.Play and (player:getMark("wq_skill_langhun_invoked") > 0 or (not player:isKongcheng()))
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    if player:getMark("wq_skill_langhun_invoked") > 0 then
      return room:askForSkillInvoke(player, self.name, data, "#wq_skill_tianbeng_prompt-noDiscard")
    elseif player:getMark("wq_skill_langhun_invoked") == 0 then
      local cids = room:askForDiscard(player, 1, 1, false, self.name, true, "slash", "#wq_skill_tianbeng_prompt-discard", true)
      if #cids > 0 then
        self.cost_data = cids
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if player:getMark("wq_skill_langhun_invoked") == 0 then
      room:throwCard(self.cost_data, self.name, player, player)
    end
    if player:isAlive() then
      room:useVirtualCard("analeptic", nil, player, player, self.name, false)
    end
    if player:isAlive() then
      local tos = room:askForChoosePlayers(player, table.map(table.filter(room:getOtherPlayers(player), function(p) return (not p:isNude()) and player:inMyAttackRange(p) end), Util.IdMapper), 1, 1, "#wq_skill_tianbeng_prompt-choose", self.name, true)
      if #tos > 0 then
        local dest = room:getPlayerById(tos[1])
        local cid = room:askForCardsChosen(player, dest, 1, 1, "he", self.name)
        if #cid > 0 then
          room:throwCard(cid, self.name, dest, player)
          if player:isAlive() and dest:isAlive() then
            room:useVirtualCard("slash", nil, player, dest, self.name, false)
          end
        end
      end
    end
  end,
}
-- 技能：横扫
local wq_skill_hengsao = fk.CreateTriggerSkill{
  name = "wq_skill_hengsao",
  anim_type = "offensive",
  events = {fk.AfterCardTargetDeclared},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) and data.card.trueName == "slash" and player.phase == Player.Play and player:usedSkillTimes(self.name, Player.HistoryPhase) == 0 then
      local targets = U.getUseExtraTargets(player.room, data, true)
      if #targets > 0 then
        self.cost_data = targets
        return true
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    if room:askForSkillInvoke(player, self.name, data, "#wq_skill_hengsao_prompt:::"..data.card:toLogString()) then
      room:doIndicate(player.id, self.cost_data)
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local targets = table.simpleClone(self.cost_data)
    room:sendLog{
      type = "#AddTargetsBySkill",
      from = player.id,
      to = targets,
      arg = self.name,
      arg2 = data.card:toLogString()
    }
    for _, pid in ipairs(targets) do
      TargetGroup:pushTargets(data.tos, pid)
    end
  end,
}
-- 技能：狼魂
local wq_skill_langhun = fk.CreateTriggerSkill{
  name = "wq_skill_langhun",
  frequency = Skill.Wake,
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.phase == Player.Start and player:usedSkillTimes(self.name, Player.HistoryGame) == 0
  end,
  can_wake = function(self, event, target, player, data)
    return player.hp <= 1
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if player:isWounded() then
      room:recover({
        who = player,
        num = 1,
        recoverBy = player,
        skillName = self.name
      })
    end
    player:drawCards(2, self.name)
    room:setPlayerMark(player, "wq_skill_langhun_invoked", 1)
  end,
}
-- 赫罗的技能
wq_heluo:addSkill(wq_skill_tianbeng)
wq_heluo:addSkill(wq_skill_hengsao)
wq_heluo:addSkill(wq_skill_langhun)
-- 赫罗的翻译
Fk:loadTranslationTable{
  ["wq_heluo"] = "赫罗",
  ["#wq_heluo"] = "力量战纹",
  ["designer:wq_heluo"] = "妙霄",
  ["cv:wq_heluo"] = "官方",
  ["illustrator:wq_heluo"] = "官方",
  ["wq_skill_tianbeng"] = "天崩",
  [":wq_skill_tianbeng"] = "出牌阶段开始时，你可以弃置一张【杀】，视为使用一张【酒】。若如此做，你可以弃置攻击范围内一名其他角色的一张牌，视为对其使用一张【杀】。",
  ["$wq_skill_tianbeng"] = "哼，这下知道我的厉害了吧！",
  ["#wq_skill_tianbeng_prompt-discard"] = "天崩：你可以弃置一张【杀】，视为使用一张【酒】",
  ["#wq_skill_tianbeng_prompt-noDiscard"] = "天崩：你可以视为使用一张【酒】",
  ["#wq_skill_tianbeng_prompt-choose"] = "天崩：你可以弃置攻击范围内一名其他角色的一张牌，视为对其使用一张【杀】",
  ["wq_skill_hengsao"] = "横扫",
  [":wq_skill_hengsao"] = "出牌阶段限一次，当你使用【杀】指定目标时，你可以令所有其他角色均成为此【杀】的目标。",
  ["$wq_skill_hengsao"] = "军团，出征！",
  ["#wq_skill_hengsao_prompt"] = "横扫：你可以令所有其他角色均成为此%arg的目标",
  ["wq_skill_langhun"] = "狼魂",
  [":wq_skill_langhun"] = "觉醒技，准备阶段，若你的体力值不大于1，你回复1点体力并摸两张牌，然后本局游戏你发动技能【天崩】时不再需要弃置【杀】。",
  ["$wq_skill_langhun1"] = "从今以后，军团，就交给我吧。",
  ["$wq_skill_langhun2"] = "我现在很强，没人再把我当作累赘了。",
  ["~wq_heluo"] = "我们……不会输……",
}

return extension